﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HCQ2_Model.ViewModel.WebAPI
{
    /// <summary>
    ///  WebApi返回模型
    /// </summary>
    public class WebApiResultJsonModel
    {
        /// <summary>
        ///  返回编码
        /// 0：成功
        /// 101：发生异常
        /// 102：认证失败
        /// 100：已完成
        /// </summary>
        public int errcode { get; set; }
        /// <summary>
        ///  返回提示消息
        /// </summary>
        public string errmsg { get; set; }
        /// <summary>
        ///  返回数据
        /// </summary>
        public object value { get; set; }

        /// <summary>
        /// 实例化一个模型
        /// </summary>
        public WebApiResultJsonModel() { }

        /// <summary>
        /// 实例化一个模型
        /// </summary>
        /// <param name="code">代码</param>
        /// <param name="msg">消息</param>        
        public WebApiResultJsonModel(int code, string msg)
        {
            this.errcode = code;
            this.errmsg = msg;            
        }
        /// <summary>
        /// 实例化一个模型
        /// </summary>
        /// <param name="code">代码</param>
        /// <param name="msg">消息</param>
        /// <param name="v">数据</param>
        public WebApiResultJsonModel(int code,string msg,object v) 
        {
            this.errcode = code;
            this.errmsg = msg;
            this.value = v;
        }
    }

    /// <summary>
    /// WebApi返回模型泛型版本
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class WebApiResultJsonModel<T>
    {
        /// <summary>
        ///  返回编码
        /// 0：成功
        /// 101：发生异常
        /// 102：认证失败
        /// 100：已完成
        /// </summary>
        public int errcode { get; set; }
        /// <summary>
        ///  返回提示消息
        /// </summary>
        public string errmsg { get; set; }
        /// <summary>
        ///  返回数据
        /// </summary>
        public T value { get; set; }

        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="errcode">编码：0成功、101发生异常、102认证失败、100已完成</param>
        /// <param name="errmsg">消息</param>
        /// <param name="value">数据</param>
        public WebApiResultJsonModel(int errcode, string errmsg, T value)
        {
            this.errcode = errcode;
            this.errmsg = errmsg;
            this.value = value;
        }

        public WebApiResultJsonModel() { }
    }
}
